#include "HighscoreState.h"

#include "..\Game.h"

#include "..\..\SGD Wrappers\SGD_GraphicsManager.h"

#include "..\Bitmap Font\BitmapFont.h"

#include "..\..\SGD Wrappers\SGD_InputManager.h"

#include "MenuState.h"

#include "..\Definitions.h"

#include <sstream>

HighscoreState* HighscoreState::GetInstance(void)
{
	static HighscoreState s_Instance;

	return &s_Instance;
}

void HighscoreState::Enter()
{

}

void HighscoreState::Exit()
{

}

bool HighscoreState::Update(float dt)
{
	Game* game = GAME;
	SGD::InputManager* Input = SGD::InputManager::GetInstance();

	if (KEYESCAPE)
		GAME->ChangeState(MenuState::GetInstance());

	return true;
}

void HighscoreState::Render()
{
	SGD::GraphicsManager* g = SGD::GraphicsManager::GetInstance();
	Game* game = GAME;

	game->GetBitmapFont()->Render("Time Attack Highscores", SGD::Point{ 75, 100 }, 1.0f, SGD::Color{ 255, 0, 0 });

	std::ostringstream oss;
	int min, sec, mil;
	min = sec = mil = 0;

	for (int i = 0; i < 5; i++)
	{
		min = game->GetHighScore(i) / 10000;
		sec = (int)((game->GetHighScore(i) / 10000.0f - min) * 100);
		mil = (int)((((game->GetHighScore(i) / 10000.0f - min) * 100.0f) - sec) * 100);

		oss << i + 1 << ".  " << min << "min " << sec << "sec " << mil << "mil   left";
		game->GetBitmapFont()->Render(oss.str().c_str(), SGD::Point{ 75.f, 50.f * i + 200.0f }, 0.5f, SGD::Color{ 255, 0, 0 });

		// Clear the oss
		oss.str("");
		oss.clear();
	}
}